<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: rgb(68, 206, 206);
            position: relative;
            left: 0;
            top: 0;
        }
    </style>

</head>

<body>
    <div id="ball"></div>

    <script>
        function createRandom(min = 0, max = 0) {
            // min>max交换值
            if (min > max) {
                [min, max] = [max, min];
            }
            let random = parseInt(Math.random() * (max - min + 1) + min);
            return random;
        }
        let x = 1, y = 1, x1 = 3, y1 = 5;
        let ball = document.getElementById('ball');

        let maxX = innerWidth - ball.offsetWidth;
        let maxY = innerHeight - ball.offsetHeight;


        let timer = setInterval(function () {
            if (x >= maxX || x <= 0) {
                x1 = -x1;
            }
            if (y >= maxY || y <= 0) {
                y1 *= -1
            }

            x = x1 + x
            y = y1 + y
            ball.style.cssText = `
            left:${x}px;
            top:${y}px;
            `
        }, 5)






    </script>











</body>

</html>